//index.js
//获取应用实例
const app = getApp()
var self,school;
var loginid;
Page({
  data: {
    swiperList: null,
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    login_view: {
      show: true
    },
    gonggaoList:[],
    msgCount:0
  },
  jumpScan:function(){
    wx.navigateTo({
      url: '/pages/scan/scan',
    })
  },
  getScancode:function(){
    wx.scanCode({
      success: (res) => {
        console.log(res)
        var result = res.result;
        var scanType = res.scanType;
        var charSet = res.charSet;
        var path = res.path;
        this.setData({
          result: result,

        })
      }
    })
  },
  onLoad: function() {
    self = this;
    
    this.getswiper();
    
  },
  goUrl: function () {
    school = wx.getStorageSync("school") || "";
    if (school == "" || school == null) {
      wx.navigateTo({
        url: '/pages/school/school',
      })
    }else{
      school = wx.getStorageSync("school");
    }
  },
  goChatlist:function(){
    var loginid = app.checkLogin();
    if(!loginid){
      return false;
    }
    wx.navigateTo({
      url: '/pages/indexAll/list_message/list_message',
    })

  },
  //获取消息数量
  getMsgCount:function(){
    wx.request({
      url: app.globalData.apiUrl + "IS04/HIS040100.ashx?Method=GetXiaoXiCount",
      data: {
        LoginID: loginid
      },
      method: 'GET',
      success: function (res) {
        console.log(res);
        if (res.data.state == 1) {
           self.setData({
             msgCount: res.data.retData.XiaoXiCount
           })
        }
      }
    });
  },
  //获取首页幻灯片
  getswiper: function() {
    wx.request({
      url: app.globalData.apiUrl + "IS13/HIS130200.ashx?Method=GetWenDangList",
      data: {},
      method: 'GET',
      success: function (res) {
        console.log(res);
        if(res.data.state==1){
          var swiperList = res.data.retData.Banner;
          for(var i=0;i<swiperList.length;i++){
            swiperList[i].TuPianURL = school.url + swiperList[i].TuPianURL;
          }
          var gonggaoList = res.data.retData.TongZhiGongGao;
          self.setData({
            swiperList: swiperList,
            gonggaoList: gonggaoList
          })
        }
      }
    });
  },
  goDetail:function(e){
    console.log(e.currentTarget.dataset.id);
    wx.navigateTo({
      url: '/pages/detail_gg/detail_gg?id=' + e.currentTarget.dataset.id,
    })
  },
  setUserInfo: function(e) {
    if (e.detail.userInfo) {
      app.login();
      app.userInfoReadyCallback = res => {
        this.setData({
          login_view: {
            show: false,
          }
        })
      }
    } else {
      wx.showToast({
        title: "为了您更好的体验,请先同意授权",
        icon: 'none',
        duration: 2000
      });
    }
  },
  goSearch() {
    wx.navigateTo({
      url: '/pages/indexAll/search/search',
    })
  },
  goYiqi() {
    wx.navigateTo({
      url: '/pages/indexAll/yiqiList/yiqiList',
    })
  },
  goShiyan() {
    wx.navigateTo({
      url: '/pages/indexAll/shiyanList/shiyanList',
    })
  },
  goSchool(){
    wx.navigateTo({
      url: '/pages/school/school',
    })
  },
  onShow:function(e){
    loginid = wx.getStorageSync('user') == "" ? -999 : wx.getStorageSync('user').UserID;
    self.goUrl();
    self.getMsgCount();
  }
})